package com.sicheng.蓝桥.练习题.基础数论.高精度;

import java.util.Scanner;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/5/18 15:04
 */
public class 大数除法 {
    static int r;

    //除法的思路
    // 数组A[]: 1  2  6
    // 数b      25
    // 模拟过程
    // 初始化余数r = 0
    // ((r = 0) * 10 + (A[0] = 1)) / 25 = 0 ... r = 1
    // ((r = 1) * 10 + (A[1] = 2)) / 25 = 0 ... r = 12
    // ((r = 12) * 10 + (A[2] = 2)) / 25 = 5 ... r = 1
    // A遍历完，得到商和余数
    //
    // 初始化余数r = 0
    // 计算乘法r = r * 10 + A[i]    其中A[i]为数组中的第i个数, b为数, r用来存储当前的结果
    // 计算结果值               r / 10
    // 计算余数，用于下次计算   r = r / 10
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        int b = sc.nextInt();
        String res = div(a.toCharArray(), b);
        System.out.println(res);
        System.out.println(r);
    }

    public static String div(char[] A, int b) {
        StringBuilder sb = new StringBuilder();
        r = 0;
        for (char a : A) {
            r = r * 10 + a - '0';
            sb.append(r / b);
            r %= b;
        }
        String s = sb.toString();
        int i = 0;
        for (; i < s.length() - 1; i++) {
            if (s.charAt(i) != '0')
                break;
        }
        return s.substring(i);
    }

}
